/*
 * Copyright (c) 2019 DawnFramework. All Rights Reserved.
 * Licensed under the MIT (LICENSE) license.
 */

package org.dawn.common.core.utils;

import org.dawn.common.core.enums.IEnum;

/**
 * @author Willard.Hu on 2017/9/29.
 */
public class Enums {

    public static <T extends IEnum> T ofCode(Object code, Class<T> enumClz) {
        T[] arr = enumClz.getEnumConstants();
        if (arr == null || arr.length == 0) {
            return null;
        }
        for (T i : arr) {
            if (i.code().equals(code)) {
                return i;
            }
        }
        return null;
    }
}
